<template>
	<view class="appPage">
		<loadingC v-if="pageLoading"></loadingC>
		<view class="title">
			<view class="name">{{dev_id=='39292'?'南岗':dev_id=='39255'?'道里':'哈尔滨'}}店</view>
		</view>
		<view class="head">

			<view class="goodsInfo">
				<view class="top" v-for="item in info.goods_list" :key="item.id">
					<view class="goodsDesc">
						<!-- <image class="img" :src="'http://chuku.snowmetal.cn'+item.cimage"></image> -->
						<view class="goods_xx">
							<view class="goodsName">{{item.name}}</view>

							<view class="count">
								X<text>{{item.num}}</text>件
							</view>
						</view>

					</view>
					<view class="jz">货架号：<text>{{item.jz}}</text> </view>
					<view class="tip" v-if="item.num>1">注意多件</view>
				</view>
				<view class="bottom">
					共计<text>{{info|count}}</text>件商品
				</view>
			</view>

		</view>
		<view class="xxx">
			<view class="name">配送信息</view>
			<view class="sendInfo">
				<view class="txt">订单编号</view>
				<view class="txt">{{info.order_no}}</view>
			</view>
		</view>
		<!-- <view class="btn" @click="trigger">开锁</view> -->
		<view class="btn" @click="call">客服电话</view>
	</view>
</template>

<script>
	import {
		apiOpendoork
	} from '@/api/common.js'
	export default {
		data() {
			return {
				pageLoading: true,
				clock: 'close',
				loading: false,
				dev_id: '39255',
				dev_pwd: 'ag639',
				info: {},
				url: ''
			}
		},
		filters: {
			count(item) {
				try {
					return item.goods_list.reduce((prev, cur) => {
						return prev + cur.num
					}, 0)
				} catch (e) {
					return 0 //TODO handle the exception
				}
			}
		},
		onLoad(option) {
			console.log('this.info');
			try {
				this.info = option.args ? JSON.parse(decodeURIComponent(option.args)) : {}
				console.log(this.info);
				this.dev_id = this.info.dev_id || '39255'
				this.dev_pwd = this.info.dev_pwd || 'ag639'
			} catch (e) {
				this.info = {}
			}
			this.pageLoading = true
			setTimeout(() => {
				this.pageLoading = false
			}, 1000)
		},
		onShow() {
			this.clock = 'close'
		},
		methods: {
			call() {
				uni.makePhoneCall({
					phoneNumber: '15561855708'
				})
			},
			trigger() {
				if (this.clock == 'opening' || this.clock == 'open') return false
				this.loading = true
				this.clock = 'opening'
				if (this.dev_id == '39255') {
					this.url = 'https://chuku.snowmetal.cn'
				} else if (this.dev_id == '39292') {
					this.url = 'https://chuku2.snowmetal.cn'
				} else if (this.dev_id == '39430') {
					this.url = 'https://chuku3.snowmetal.cn'
				}
				apiOpendoork(this.url +
					'/index/user/opendoor.html', {
						dev_id: this.dev_id,
						dev_pwd: this.dev_pwd
					}).then(res => {
					if (res == 'success') {
						uni.showToast({
							title: '已开锁',
							icon: 'none',
							duration: 2000,
							mask: true
						})
						this.clock = 'close'
						this.loading = false

						// setTimeout(() => {
						// 	uni.navigateTo({
						// 		url: '/pages/input/index'
						// 	})

						// }, 2000)
					} else {
						this.clock = 'close'
						this.loading = false
						uni.showToast({
							title: '开锁失败，请重试（或联系管理员）',
							icon: 'none',
							duration: 3000,
							mask: true
						})
					}

				})

			}
		}
	}
</script>

<style scoped lang="scss">
	.appPage {
		width: 100%;
		height: 100vh;
		background-color: #f5f5f5;
		// display: flex;
		// flex-direction: column;
		// align-items: center;
		position: relative;
		box-sizing: border-box;

		.title {
			color: #fff;
			font-size: 32rpx;
			background-color: #fe5d49;
			padding: 20rpx;

			.name {
				margin-bottom: 10rpx;
			}

			.desc {
				font-size: 28rpx;
			}
		}

		.head {
			padding-left: 20rpx;
			box-sizing: border-box;
			margin-top: 20rpx;

			.goodsName {
				font-size: 36rpx;
				font-weight: 600;

				text {
					color: #f29c41;
				}
			}

			.goodsInfo {
				background-color: #fff;
				width: 710rpx;
				border-radius: 20rpx;
				position: relative;

				.top {
					margin-top: 20rpx;
					display: flex;
					align-items: center;
					justify-content: space-between;

					.jz {
						font-size: 36rpx;
						position: absolute;
						right: 20rpx;
						top: 20rpx;

						text {
							color: #f29c41;
							margin-left: 10rpx;
						}
					}

					.goodsDesc {
						padding: 20rpx;
						box-sizing: border-box;
						display: flex;
						align-items: center;

						.img {

							width: 200rpx;
							height: 200rpx;
							border-radius: 20rpx;
							background-color: #ddd;
							margin-right: 20rpx;
						}

						.goods_xx {
							height: 200rpx;
							display: flex;
							flex-direction: column;
							justify-content: space-between;
							padding: 10rpx 0;
							box-sizing: border-box;

							.goodsName {
								font-size: 48rpx;
								margin-bottom: 50rpx;
							}

							.count {
								font-size: 42rpx;
								font-weight: bold;

								text {
									// font-weight: normal;
									font-size: 52rpx;
									color: #f29c41;
									margin: 0 20rpx;
								}
							}
						}

					}

					.tip {
						color: #f29c41;
						margin-right: 20rpx;
						font-size: 28rpx;
					}
				}

				.bottom {
					border-top: 1rpx solid #ddd;
					padding: 30rpx 20rpx;
					box-sizing: border-box;
					text-align: right;

					text {
						color: #f29c41;
						font-size: 40rpx;
						font-weight: bold;
						margin: 0 10rpx;
					}
				}
			}
		}

		.xxx {
			padding: 40rpx 20rpx 20rpx;
			box-sizing: border-box;

			.name {
				font-weight: bold;
				font-size: 32rpx;
			}

			.sendInfo {
				margin-top: 20rpx;
				display: flex;
				align-items: center;
				justify-content: space-between;
			}
		}

		.btn {
			width: 710rpx;
			background-color: #000;
			color: #fff;
			font-size: 28rpx;
			padding: 30rpx 0;
			margin-top: 40rpx;
			text-align: center;
			margin-left: 20rpx;
			border-radius: 20rpx;
		}

		// .tip {
		// 	height: 40rpx;
		// 	font-size: 32rpx;
		// 	color: #999;
		// 	text-align: center;
		// 	position: absolute;
		// 	top: calc(50%);
		// 	left: 50%;
		// 	transform: translateX(-50%);
		// }

		// .clock {
		// 	width: 150rpx;
		// 	height: 150rpx;
		// 	border-radius: 50%;
		// 	display: flex;
		// 	align-items: center;
		// 	justify-content: center;

		// 	.iconfont {
		// 		font-weight: 600;
		// 		font-size: 120rpx;
		// 	}
		// }

		// .close {
		// 	color: rgba(255, 0, 0, 1);
		// 	border: 20rpx solid rgba(255, 0, 0, .8);
		// 	box-shadow: 0rpx 0 15rpx 15rpx rgba(255, 0, 0, .2) inset;
		// 	position: relative;

		// 	.box1 {
		// 		width: 190rpx;
		// 		height: 190rpx;
		// 		content: '';
		// 		border: 20rpx solid rgba(255, 0, 0, .5);
		// 		border-radius: 50%;
		// 		position: absolute;
		// 		left: -40rpx;
		// 		top: -40rpx;

		// 		.box2 {
		// 			width: 230rpx;
		// 			height: 230rpx;
		// 			content: '';
		// 			border: 20rpx solid rgba(255, 0, 0, .2);
		// 			border-radius: 50%;
		// 			display: flex;
		// 			align-items: center;
		// 			justify-content: center;
		// 			position: absolute;
		// 			left: -40rpx;
		// 			top: -40rpx;
		// 		}
		// 	}
		// }

		// .opening {
		// 	width: 270rpx;
		// 	height: 270rpx;
		// 	animation: animation 1.5s linear infinite;
		// 	border-radius: 50%;
		// 	position: absolute;
		// 	top: -60rpx;
		// 	left: -60rpx;
		// 	z-index: 2;
		// }

		// @keyframes animation {
		// 	0% {
		// 		box-shadow: 0 0 0rpx 60rpx rgba(255, 255, 255, .6) inset;
		// 	}

		// 	100% {
		// 		box-shadow: 0 0 0rpx 0rpx rgba(255, 255, 255, .6) inset;
		// 	}
		// }

		// .close {
		// 	color: rgba(255, 0, 0, 1);
		// 	border: 20rpx solid rgba(255, 0, 0, .8);
		// 	box-shadow: 0rpx 0 15rpx 15rpx rgba(255, 0, 0, .2) inset;
		// 	position: relative;

		// 	.box1 {
		// 		width: 190rpx;
		// 		height: 190rpx;
		// 		content: '';
		// 		border: 20rpx solid rgba(255, 0, 0, .5);
		// 		border-radius: 50%;
		// 		position: absolute;
		// 		left: -40rpx;
		// 		top: -40rpx;
		// 	}

		// 	.box2 {
		// 		width: 230rpx;
		// 		height: 230rpx;
		// 		content: '';
		// 		border: 20rpx solid rgba(255, 0, 0, .2);
		// 		border-radius: 50%;
		// 		display: flex;
		// 		align-items: center;
		// 		justify-content: center;
		// 		position: absolute;
		// 		left: -60rpx;
		// 		top: -60rpx;
		// 	}
		// }

		// .open {
		// 	color: rgba(122, 215, 204, 1);
		// 	border: 20rpx solid rgba(122, 215, 204, .8);

		// 	box-shadow: 0rpx 0 15rpx 15rpx rgba(122, 215, 204, .2) inset;
		// 	position: relative;

		// 	&::before {
		// 		width: 190rpx;
		// 		height: 190rpx;
		// 		content: '';
		// 		border: 20rpx solid rgba(122, 215, 204, .5);
		// 		border-radius: 50%;
		// 		position: absolute;
		// 		left: -40rpx;
		// 		top: -40rpx;
		// 	}

		// 	&::after {
		// 		width: 230rpx;
		// 		height: 230rpx;
		// 		content: '';
		// 		border: 20rpx solid rgba(122, 215, 204, .2);
		// 		border-radius: 50%;
		// 		position: absolute;
		// 		left: -60rpx;
		// 		top: -60rpx;
		// 	}
		// }

	}
</style>